<!DOCTYPE html>
<html  xmlns:th="http://www.thymeleaf.org">
<head>
    
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="robots" content="all,follow">

    <title>合同管理</title>
    <link rel="shortcut icon" href="/img/favicon.ico">
    
    <!-- global stylesheets -->
    <link href="https://fonts.googleapis.com/css?family=Roboto+Condensed" rel="stylesheet">
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <link rel="stylesheet" href="/font-awesome-4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/font-icon-style.css">
    <link rel="stylesheet" href="/css/style.default.css" id="theme-stylesheet">

    <!-- Core stylesheets -->

    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#goTo").on("click", function () {
                window.location.assign("/contract/downloadContractList?pageNum=" + $("#pageNum").val());
            });
        });

        function editInfo(id) {
            $.ajax({
                //请求方式
                type: "POST",
                //请求的媒体类型
                dataType: "json",
                //请求地址
                url: "/contract/editDownloadContract",
                //数据，json字符串
                data: {"id": id},
                //请求成功
                success: function (data) {
                    $("#name").val(data.name);
                    $("#remark").val(data.contractRecord.remark);
                    if(data.contractType=='销售合同') $("#销售合同").attr("selected", true);
                    else if(data.contractType=='采购合同') $("#采购合同").attr("selected", true);
                    else if(data.contractType=='保密合同') $("#保密合同").attr("selected", true);
                    $("#att").attr("href", "/contract/download?id="+data.att.id);
                    $("#att").text(data.att.name.substr(data.att.name.indexOf("_")+1));
                    $("#contractId").val(data.id);
                    $("#contractRecordId").val(data.contractRecord.id);
                    $("#attId").val(data.att.id);
                }
            });
        }

    </script>

</head>

<body> 
<!--====================================================
                        PAGE CONTENT
======================================================-->
    <div class="content-inner form-cont">
            <div class="row">
                <div class="col-md-12">

                    <!--***** BASIC FORM *****-->
                    <div class="card form" id="form1">
                        <div class="card-header">
                            <h3>下载合同</h3>
                        </div>
                        <br>
                        <form name="searchContractForm" th:action="@{/contract/searchDownloadContract}" method="post">

                            <div class="row">
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label for="example-text-input" style="width: 85px;margin-left: 20px;" class=" col-form-label">合同标题</label>
                                        <div class="col-9">
                                            <input name="name" class="form-control" type="text" >
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label style="width: 85px;margin-left: 20px;"  class=" col-form-label">合同分类</label>
                                        <div class="col-9">
                                            <select name="type" class="form-control">
                                                <option value="">选择类型</option>
                                                <option value="销售合同">销售合同</option>
                                                <option value="采购合同">采购合同</option>
                                                <option value="保密合同">保密合同</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <button type="submit" class="btn btn-general btn-blue mr-2" style="margin-left: 50px;margin-bottom: 20px; float: left;">查询</button>  
                            <button type="reset" class="btn btn-general btn-white">重置</button> 
                        </form>
                    </div>
                </div>
            </div>
    <div class="page-content d-flex align-items-stretch">
        <div class="content-inner chart-cont">
            <!--***** CONTENT *****-->     
            <div class="row">
              <button type="button" class="btn btn-outline-primary" data-toggle="modal" data-target="#newTemplate">添加模板</button>
                <table class="table table-hover" >
                    <thead>
                    <tr class="bg-info text-white" >
                        <th>id</th>
                        <th>合同标题</th>
                        <th>合同分类</th>
                        <th>编辑时间</th>
                        <th>状态</th>
                        <th style="text-align: center;">操作</th>
                    </tr>
                    </thead>
                    <tbody id="table-detail">
                    <tr th:each="contract:${page.list}">
                        <th th:text="${contract.id}" scope="row">1</th>
                        <td th:text="${contract.name}">模板1</td>
                        <td th:text="${contract.contractType}">xx类</td>
                        <td th:text="${contract.updateTime}">dwqfwawfzfx</td>
                        <td th:text="${contract.contractRecord}?((${contract.contractRecord.hasShare}=='是')?'启用':'禁用')">启用</td>
                        <td style="text-align: center;">
                            <a id="edit" href="#" data-toggle="modal" data-target="#updateTemplate" th:onclick="'javascript:editInfo('+${contract.id}+')'">编辑|</a>
                            <a href="#" th:href="@{~/contract/deleteDownloadContract(contractId=${contract.id},attId=${contract.att.id},path=${#request.getServletPath()})}">删除|</a>
                            <a href="#" th:href="@{~/contract/switchShareStatus(id=${contract.id},path=${#request.getServletPath()})}" th:text="${contract.contractRecord}?((${contract.contractRecord.hasShare}=='是')?'禁用':'启用')">暂无</a>
                        </td>
                    </tr>
                    </tbody>
                </table>
                <div  class="c-pages">
                  <div class="cp-item">
                      <span>共</span>
                      <span th:text="${page.total}">0</span>
                      <span>条</span>
                  </div>
                  <div class="cp-item">
                      <span th:text="${page.pageNum}">1</span>
                      <span>/</span>
                      <span th:text="${page.pages}">1</span>
                  </div>
                  <div class="cp-item">
                      <a th:href="@{~/contract/downloadContractList(pageNum=1)}"><button id="home" class="btn btn-outline-primary">首页</button></a>
                      <a th:href="@{~/contract/downloadContractList(pageNum=${page.pageNum -1})}"><button id="prev" class="btn btn-outline-primary">上页</button></a>
                      <input name="pageNum" type="number" id="pageNum"/>
                      <button id="goTo" class="btn btn-outline-primary">转到</button>
                      <a th:href="@{~/contract/downloadContractList(pageNum=${page.pageNum+1})}"><button id="next" class="btn btn-outline-primary">下页</button></a>
                      <a th:href="@{~/contract/downloadContractList(pageNum=${page.pages})}"><button id="last" class="btn btn-outline-primary">尾页</button></a>
                  </div>
                  
                </div>
            </div> 

        </div>
    </div> 
    </div>
    
    <!-- 添加模板模态框（Modal） -->
    <div class="modal fade" id="newTemplate" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
      <div class="modal-dialog">
          <div class="modal-content">
              <div class="modal-header">
                  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                      &times;
                  </button>
                  <h4 class="modal-title" id="myModalLabel">
                      新增模板
                  </h4>
              </div>
              <form method="post" th:action="@{~/contract/addDownloadContract}" enctype="multipart/form-data">
              <div class="modal-body">
                  <div class="form-group row">
                      <label for="example-text-input" style="width: 85px;margin-left: 20px;" class=" col-form-label">合同标题：</label>
                      <div class="col-9">
                          <input  class="form-control" type="text" name="name" value="">
                      </div>
                  </div>
                  <div class="form-group row">
                      <label for="example-text-input" style="width: 85px;margin-left: 20px;" class=" col-form-label">合同分类：</label>
                      <div class="col-9">
                          <select name="contractType" class="form-control">
                              <option value="销售合同">销售合同</option>
                              <option value="采购合同">采购合同</option>
                              <option value="保密合同">保密合同</option>
                              <!--其它合同类型-->
                          </select>
                      </div>
                  </div>
                  <div class="form-group row">
                      <label for="example-text-input" style="width: 85px;margin-left: 20px;" class=" col-form-label">简介：</label>
                      <div class="col-9">
                          <textarea name="contractRecord.remark" class="form-control" rows="5"></textarea>
                      </div>
                  </div>
                  <div class="form-group">
                      <label for="exampleInputFile" style="width: 85px;">上传模板</label>
                      <input type="file" class="form-control-file" aria-describedby="fileHelp" name="uploadFile">
                      <small id="fileHelp" class="form-text text-muted">上传修改后的模板</small>
                  </div>
              <div class="modal-footer">
                  <button type="submit" class="btn btn-primary">提交</button>
                  <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                  </button>
              </div>
            </div><!-- /.modal-content -->
              </form>
        </div><!-- /.modal -->
      </div>
    </div>
    <!-- 修改模板模态框（Modal） -->
    <div class="modal fade" id="updateTemplate" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
      <div class="modal-dialog">
          <div class="modal-content">
              <div class="modal-header">
                  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                      &times;
                  </button>
                  <h4 class="modal-title" id="myModalLabel">
                      编辑模板
                  </h4>
              </div>
              <form name="addContractForm" th:action="@{/contract/updateDownloadContract}" method="post"  enctype="multipart/form-data">
                  <div class="modal-body">
                      <div class="form-group row">
                          <label for="example-text-input" style="width: 85px;margin-left: 20px;" class=" col-form-label">合同标题：</label>
                          <div class="col-9">
                              <input id="name" class="form-control" type="text" name="name" value="">
                          </div>
                      </div>
                      <div class="form-group row">
                          <label for="example-text-input" style="width: 85px;margin-left: 20px;" class=" col-form-label">合同分类：</label>
                          <div class="col-9">
                              <select name="contractType" class="form-control">
                                  <option value="销售合同" id="销售合同">销售合同</option>
                                  <option value="采购合同" id="采购合同">采购合同</option>
                                  <option value="保密合同" id="保密合同">保密合同</option>
                                  <!--其它合同类型-->
                              </select>
                          </div>
                      </div>
                      <div class="form-group row">
                          <label for="example-text-input" style="width: 85px;margin-left: 20px;" class=" col-form-label">简介：</label>
                          <div class="col-9">
                              <textarea id="remark" name="contractRecord.remark" class="form-control" rows="5"></textarea>
                          </div>
                      </div>
                      <div class="form-group">
                          <label for="exampleInputFile" style="width: 85px;">当前模板</label>
                          <a id="att">暂无</a><br/>
                      </div>
                      <div class="form-group">
                          <label for="exampleInputFile" style="width: 85px;">重传模板</label>
                          <input type="file" class="form-control-file" aria-describedby="fileHelp" name="uploadFile">
                          <small id="fileHelp" class="form-text text-muted">重传修改后的模板</small>
                      </div>
                      <div class="modal-footer">
                          <button type="submit" class="btn btn-primary">提交</button>
                          <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                          </button>
                      </div>
                  </div><!-- /.modal-content -->
                  <input id="contractId" type="hidden" name="id"/>
                  <input id="contractRecordId" type="hidden" name="contractRecord.id"/>
                  <input type="hidden" id="attId" name="att.id"/>
              </form>

          </div><!-- /.modal -->
      </div>
    </div>
    <!--Global Javascript -->
    <script src="/js/jquery.min.js"></script>
    <script src="/js/popper/popper.min.js"></script>
    <script src="/js/tether.min.js"></script>
    <script src="/js/bootstrap.min.js"></script>
    <script src="/js/jquery.cookie.js"></script>
    <script src="/js/jquery.validate.min.js"></script>
    <script src="/js/chart.min.js"></script>
    <script src="/js/front.js"></script>
    <script src="/js/forpage.js"></script>
</body>

</html>